package org.danan.spark2hudi.bean;

import org.apache.kafka.clients.producer.KafkaProducer;
import org.apache.kafka.clients.producer.ProducerRecord;
import org.danan.spark2hudi.utils.KafkaUtil;

import java.io.Serializable;

/**
 * Created with IntelliJ IDEA.
 *
 * @Author: NanHuang
 * @Date: 2023/07/12/10:49
 * @Description:
 */
public class MyKafkaProducer implements Serializable {
    private KafkaProducer<String,String> producer;

    public MyKafkaProducer() {
        this.producer = KafkaUtil.getProducer();
    }

    public void send(String topic,String message){
        this.producer.send(new ProducerRecord<>(topic,message));
    }

    public void close(){
        this.producer.close();
    }
}
